define(['./../../initial'],
    function() {
        var app = angular.module('App.home');
        app.controller('admin.userCtrl', ['$timeout', '$scope', '$rootScope', '$state', '$stateParams', 'User', 'showMsg', 'Project', 'authorizedUsers', 'userCorps',
            function($timeout, $scope, $rootScope, $state, $stateParams, User, showMsg, Project, authorizedUsers, userCorps) {
                $scope.authorizedUsers = authorizedUsers;
                $scope.userCorps = userCorps;

                $timeout(function() {
                    $('.ui.dropdown').dropdown();
                }, 300);

                $scope.freezeUser = function(user) {
                    user.freeze = user.freeze === 1 ? 0 : 1;
                    var action = user.freeze === 1 ? '冻结' : '解冻';
                    user.postFreezeUser().then(function(data) {
                        if (data.toString() === 'true') {
                            showMsg('已成功' + action + user.realName, 'info');
                        } else {
                            showMsg(action + '失败', 'alert');
                            //rollback 回滚
                            user.freeze = user.freeze === 1 ? 0 : 1;
                        }
                    });
                };

                $scope.changeAuthen = function(user, a) {
                    var back = user.authentication;
                    user.authentication = a;
                    user.postChangeUserAuthentication().then(function(data) {
                        if (data.toString() === 'false') {
                            showMsg('设置权限失败', 'alert');
                            user.authentication = back;
                        }
                    });
                };
            }
        ]);
    });
